package com.atguigu.common.result;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class R {

    private String message;

    private Integer code;

    private Map<String,Object> data = new HashMap<>();

    private R(){}

    public R data(Map<String,Object> obj){
        this.setData(obj);
        return this;
    }

    public  R data(String key,Object obj){
        this.data.put(key,obj);
        return this;
    }

    public static R ok(){
        return R.setResponseEnum(ResponseEnum.SUCCESS);
    }

    public static R error(){
        return R.setResponseEnum(ResponseEnum.FAIL);
    }

    public static R setResponseEnum(ResponseEnum responseEnum){
        R r = new R();
        r.setCode(responseEnum.getCode());
        r.setMessage(responseEnum.getMessage());
        return r;
    }

    public String getMessage() {
        return message;
    }

    public R message(String message) {
        this.message = message;
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public R code(Integer code) {
        this.code = code;
        return this;
    }
}
